document.write('<script type="text/javascript" src="' + context
		+ '/resources/common/js/wordbook.js"></script>');

/**
 * 更新成功后回调函数
 */
function forwardFunc() {
	window.history.back(-1);
}

function viewImg(id, name) {
	var str = '<img src="' + $(id).getAttribute('url')
			+ '" width="100%" height="100%">';

	var win = new Ext.Window({
				renderTo : Ext.getBody(),
				layout : 'fit',
				width : 500,
				height : 400,
				title : name,
				resizable : true,
				plain : true,
				modal : true,
				maximizable : true,
				html : str,

				buttons : [{
							text : '下 载',
							handler : function() {
								viewAnnex(id);
							}
						}, {
							text : '关 闭',
							handler : function() {
								win.close();
							}
						}]
			});

	win.show(this);
}

/**
 * 初始化form表单项
 * 
 * @param {}
 *            json
 */
function initFunc(json) {
	inithelper();

	if (json != null && json.success == true) {
		$('nfid').value = json.data.NF_ID;
		$('qu').value = json.data.NF_QUESTION;
		// $('qutype').value = json.data.NF_QUTYPE;
		initwordbook4select('qutype', json.data.NF_QUTYPE, 'qutype', true);
		$('username').innerHTML = json.data.NF_USERNAME;
		$('groupname').innerHTML = json.data.NF_GROUPNAME;
		$('gc').innerHTML = json.data.NF_GC;
		$('bd').innerHTML = json.data.NF_BDNAME;
		$('time').innerHTML = formatDate(json.data.NF_TIME.substring(0, 8))
				+ ' ' + json.data.NF_TIME.substring(8, 10) + ':'
				+ json.data.NF_TIME.substring(10, 12);
		Ext.each(json.data.NF_FILE, function(item) {
			var id = item.id;
			var name = item.name;
			var type = item.type;

			var str = '';

			if (type == 'jpg') {
				var url = context + '/temp-store/' + item.folder + '/' + id
						+ '.data';

				str += '<div class="divn" style="width:70px;" title="查看详细" onClick="javascript:viewImg(\''
						+ id
						+ '\', \''
						+ name
						+ '\');">'
						+ '<img item="img" url="'
						+ item.url
						+ '" id="'
						+ id
						+ '" style="cursor:hand;" width="64" height="64" src="'
						+ url + '"/></div>'
			} else {
				str += '<div class="divn" style="width:70px;" title="下载文件" onclick="javascript:viewAnnex(\''
						+ id
						+ '\');">'
						+ '<img style="cursor:hand;" width="64" height="64" src="'
						+ context + '/app/file/images/file.png"/></div>'
			}

			$('filearea').innerHTML += str;
		})
	}
}

/**
 * 修改文档信息
 */
function handleUpdate() {
	updateTable('APP_NS_FILE', 'single', '-1', null, function() {
				forwardFunc();
			});
}